home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / cross / GBDK-2.0.lha / GBDK / lib / ftou.ms < prev    next >
Text File  |  1998-10-01  |  643b  |  65 lines

  1.     INCLUDE "macros.ms"
  2.     .include "math.s"
  3.     .module ftou.ms
  4.  
  5.     .area    _CODE
  6. ;    Float to unsigned
  7. .ftou::
  8.     bit    7,h
  9.     jr    z,ftou_pos
  10.     ld    a,#0
  11.     ret
  12. ftou_pos:
  13.     ld    a,h
  14.     cp    #64
  15.     jr    nc,ftou_gteqone
  16.     ld    a,#0
  17.     ret
  18. ftou_gteqone:
  19.     or    a
  20.     rr    l
  21.     rr    d
  22.     rr    e
  23.     inc    h
  24.     ld    a,h
  25.  
  26.     cp    #64+24
  27.     jr    c,ftou_gteqone
  28.     ld    a,e
  29.     ret
  30.  
  31. .ftoi::
  32.     ld    b,h
  33.     ld    a,h
  34.     and    #0x7f
  35.     ld    h,a
  36.     cp    #0x41
  37.     jr    nc,ftoi_gteqone
  38.     ld    a,#0
  39.     ret
  40. ftoi_gteqone:
  41.     cp    #0x48        ; 128 = 48800000
  42.     jr    c,ftoi_norm
  43.     ld    a,#0x7f        ; +max
  44.     bit    7,b
  45.     ret    z
  46.     ld    a,#0x80        ; -max
  47.     ret
  48. ftoi_norm:
  49.     cp    #64+8
  50.     jr    z,ftoi_done
  51.     or    a
  52.     rr    l
  53.     rr    d
  54.     rr    e
  55.     inc    h
  56.     ld    a,h
  57.     jr    ftoi_norm
  58. ftoi_done:
  59.     ld    a,l
  60.     bit    7,b
  61.     ret    z
  62.     cpl
  63.     inc    a
  64.     ret
  65.